#!/bin/bash -e
# $File: dump.sh
# $Date: Wed Jun 13 22:02:27 2012 +0800
# $Author: jiakai <jia.kai66@gmail.com>

fname=$1

if [ -z "$fname" ]
then
	echo "usage: $0 <obj filename>"
	exit -1
fi

arg=$(objdump -h $fname | grep '0 .text' | 
	(read idx name size vma lma off align;
	echo "-s 0x$off -l 0x$size"))

echo -n '"'
xxd -c 1 -ps $arg $fname | tr "\n" ' ' |
	sed -e 's/\<\(..\)\> \?/\\x\1/g'
echo '"'

